"""Build placement code"""
import daos_build

def scons():
    """Execute build"""
    Import('env', 'prereqs')

    env.AppendUnique(LIBPATH=[Dir('.')])

    prereqs.require(env, 'isal')

    denv = env.Clone()

    libraries = ['isal']

    # Common placement code
    common_tgts = denv.SharedObject(['pl_map.c', 'ring_map.c',
                                     'jump_map.c', 'pl_map_common.c'])
    # placement client library
    dc_placement_tgts = common_tgts
    Export("dc_placement_tgts")

    if not prereqs.server_requested():
        return

    # generate server module
    print("libs = %s" % denv.subst("$LIBS"))
    srv = daos_build.library(denv, 'placement', common_tgts,
                             install_off="../..", LIBS=libraries)
    denv.Install('$PREFIX/lib64/daos_srv', srv)

    if prereqs.test_requested():
        # Build tests
        SConscript('tests/SConscript', exports=['denv', 'common_tgts'])

if __name__ == "SCons.Script":
    scons()
